<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>vue学习</title>
    <script src="./js/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <div v-debounce @click="aa">{{title}}</div>
    </div>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            title: 'aaa'
          }
        },
        methods: {
          aa() {
            console.log('aaaa')
          }
        }
      })

      app.directive('debounce', {
        mounted(el, bindings, vnode) {
          let timer = null
          el.addEventListener(
            'click',
            (e) => {
              e.stopPropagation()
              if (timer) {
                clearTimeout(timer)
                timer = null
              }
              timer = setTimeout(() => {
                // binding.value()
                // console.log(vnode)
                vnode.props.onClick()
              }, 3000)
            },
            true
          )
        }
      })

      app.mount('#app')
    </script>
  </body>
</html>
